package com.joinway.framework.utils

import org.apache.commons.lang3.StringUtils;

final class GroovyUtils {

	public static final List<String> AST_FIELDS = ["toStringStyle", "class"]
	
	static void removeASTFields(def o){
		AST_FIELDS.each {
			o.metaClass."$it" = null
		}
	}
	
	static void setProperty(def bean, String prop, def value){
		bean."$prop" = value
	}
	
	static void setMethod(def bean, String fieldName, def value){
		String propName = "set" + StringUtils.capitalize(fieldName);
		bean."${propName}"(value);
	}

	static def getProperty(def bean, String prop){
		bean."$prop"
	}
	
	static void addProperty(def bean, String prop, def value){
		bean.metaClass."$prop" = value
	}
	
	static Map<String, Object> getProperties(def bean){
		bean.getProperties()
	}
	
	static boolean isTrue(def value){
		value
	}
	
	static def createGroovyObject(){
		new Object()
	}
	
	private GroovyUtils(){}
	
}
